package com.zyd.io.page;

import java.util.HashMap;

public class PageRequestBean extends HashMap<String, Object> {

    private static final String CURRENT_PAGE = "currentPage";

    private static final String PAGE_SIZE = "pageSize";

    private static final int DEFAULT_CURRNET_PAGE = 1;

    private static final int DEFAULT_PAGE_SIZE = 20;

    public int getCurrentPage() {
        return getInt(CURRENT_PAGE, DEFAULT_CURRNET_PAGE);
    }

    public int getPageSize() {
        return getInt(PAGE_SIZE, DEFAULT_PAGE_SIZE);
    }

    public int getInt(String key, int defaultValue) {
        Object ret;
        if ((ret = get(key)) != null) {
            if (ret instanceof String) {
                return Integer.valueOf(ret.toString());
            } else if (ret instanceof Integer) {
                return ((Integer) ret).intValue();
            } else {
                return Integer.valueOf(ret.toString());
            }
        }
        return defaultValue;
    }

    public String getString(String key) {
        Object ret;
        if ((ret = get(key)) != null) {
            if (ret instanceof String) {
                return ret.toString().trim();
            } else if (ret instanceof Integer) {
                return String.valueOf(ret).trim();
            } else {
                return ret.toString().trim();
            }
        }
        return null;
    }


}
